package com.springsummer.information.green.webmvc.controllers;

import com.alibaba.fastjson.JSON;

import com.springsummer.information.green.annotation.Autowired;
import com.springsummer.information.green.annotation.Controller;
import com.springsummer.information.green.annotation.RequestMapping;
import com.springsummer.information.green.annotation.ResponseBody;
import com.springsummer.information.green.webmvc.ModelAndView;

import java.util.List;

@Controller
public class HelloEmpsController {

    @Autowired
    private HelloEmpsService helloEmpsService;

    @RequestMapping(path = "/emp/add")
    @ResponseBody
    public EmpsVo empAdd(String name, Integer age, String phone){
        //访问地址 http://localhost:8080/emp/add?name=pingping&age=18&phone=123456789
        EmpsVo userVo=new EmpsVo();
        userVo.setStudentName("name:"+name);
        userVo.setAge(age);
        userVo.setPhone("phone:"+phone);
        userVo.setTeacherName("萍萍");
        System.out.println(getClass().getName()+" helloModel model:"+ JSON.toJSONString(userVo));
        return userVo;
    }

    @RequestMapping(path = "/emp/list")
    @ResponseBody
    public List<EmpsVo> empList(String name, Integer age, String phone){
        EmpsVo userVo=new EmpsVo();
        userVo.setStudentName("helloTwo:"+name);
        userVo.setAge(age);
        userVo.setPhone("helloTwo:"+phone);
        userVo.setTeacherName("萍萍");
        System.out.println(getClass().getName()+" helloUserTwo model:"+ JSON.toJSONString(userVo));
        return helloEmpsService.queryEmps(name,age,phone);
    }

    @RequestMapping(path = "/emp/empViewPage")
    public ModelAndView empViewPage(String name, Integer age, String phone){

        EmpsVo userVo=new EmpsVo();
        userVo.setStudentName("helloTwo:"+name);
        userVo.setAge(age);
        userVo.setPhone("helloTwo:"+phone);
        userVo.setTeacherName("萍萍");
        System.out.println(getClass().getName()+" empViewPage model:"+ JSON.toJSONString(userVo));
        ModelAndView modelAndView=new ModelAndView("/static/empView");
        modelAndView.addObject("namestr",userVo.getStudentName());
        return modelAndView;
    }

    @RequestMapping(path = "/emp/empViewPageRetwo")
    public ModelAndView empViewPageRetwo(String name, Integer age, String phone){

        EmpsVo userVo=new EmpsVo();
        userVo.setStudentName("helloTwo:"+name);
        userVo.setAge(age);
        userVo.setPhone("helloTwo:"+phone);
        userVo.setTeacherName("萍萍");
        System.out.println(getClass().getName()+" empViewPage model:"+ JSON.toJSONString(userVo));
        ModelAndView modelAndView=new ModelAndView("redirect:/static/empView");
        modelAndView.addObject("namestr",userVo.getStudentName());
        return modelAndView;
    }

}
